<template>
    <nav class="ge-cdx-header-redesign__menu-container">
        <ul class="ge-cdx-header-redesign__menu-container__nav-menu-list">
            <li v-for="item of props.menuData" :key="'menu' + item.id" class="ge-cdx-header-redesign__nav-menu-item">
                <span :ref="item.code" class="ge-cdx-header-redesign__nav-menu-item__nav-link"
                    :class="props.currentMenuUrl === item.code ? 'is-active' : ''" @click="menuChange(item)"
                    >{{ item.name }}</span>
                <div v-if="props.currentMenuUrl === item.code" class="ge-cdx-header-redesign__nav-menu-item__active-menu-item">
                </div>
            </li>
        </ul>
    </nav>
</template>
<script setup>
import { defineProps, defineEmits } from 'vue'
const props = defineProps(['currentMenuUrl', 'menuData'])
let emit = defineEmits(['menu-change'])
function menuChange(menuItem) {
    if (props.currentMenuUrl.value === menuItem.code) {
        emit('menu-change', '')
    } else {
        emit('menu-change', menuItem)
    }    
}
</script>
<style lang="scss" scoped>
.ge-cdx-header-redesign__menu-container {
    display: flex;
    float: none;
    position: relative;
    z-index: 1002;
    box-sizing: border-box;
}

.ge-cdx-header-redesign__menu-container__nav-menu-list {
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
    padding: 0;
    margin: 0;
    align-items: center;
    box-sizing: border-box;
}

.ge-cdx-header-redesign__nav-menu-item {
    position: relative;
    margin: 12px;
    box-sizing: border-box;
}

.ge-cdx-header-redesign__nav-menu-item__nav-link {
    max-width: 22ch;
    font-weight: 400;
    font-size: 0.875rem;
    line-height: 24px;
    color: #222222;
    padding-bottom: 32px;
    padding-top: 10px;
    margin-top: 22px;
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: pointer;
}

.is-active {
    color: var(--interaction);
}

.ge-cdx-header-redesign__nav-menu-item__active-menu-item {
    height: 4px;
    width: 100%;
    background: var(--interaction);
    position: absolute;
    bottom: 4px;
}
</style>